from datetime import datetime
from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()


class BaseModel(db.Model):
    __abstract__ = True

    create_time = db.Column(db.DateTime, default=datetime.now, nullable=False, comment='创建时间')
    last_update_time = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now, nullable=False,
                                 comment='最后修改时间')

    def to_dict(self):
        return {c.key: getattr(self, c.key) for c in self.__table__.columns}

